package models;

import enums.LogisticsStatus;
import models.constants.DeletedStatus;
import order.AdminOrder;

import javax.persistence.*;
import java.util.List;

/**
 * Created by liming on 16/8/2.
 * 物流明细
 */
@Entity
@Table(name = "admin_express_order")
public class AdminExpressOrder extends BaseModel {

    /**
     * 物流单
     */
    @ManyToOne
    @JoinColumn(name = "admin_express_id")
    public AdminExpress adminExpress;

    /**
     * 订单
     */
    @ManyToOne
    @JoinColumn(name = "admin_order_id")
    public AdminOrder adminOrder;

    /**
     * 物流状态
     */
    @Column(name = "logistics_status")
    @Enumerated(EnumType.STRING)
    public LogisticsStatus logisticsStatus;

    /**
     * 查询某物流单下的所有订单
     */
    public static List<AdminExpressOrder> loadExpressOrderList(long adminExpressId){
        return AdminExpressOrder.find("adminExpress.id=? and adminOrder.deleted =?",adminExpressId, DeletedStatus.UN_DELETED).fetch();
    }


}
